package com.example.hm_dtfkz.util;

import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.appcompat.widget.LinearLayoutCompat;

import com.airbnb.lottie.LottieAnimationView;
import com.binioter.guideview.Component;
import com.example.hm_dtfkz.R;

public class GuideComponent implements Component {
    private OnGuideClickLister guideLister;

    public int guideIndex = 0;

    @Override
    public View getView(LayoutInflater inflater) {

        LinearLayoutCompat ll = (LinearLayoutCompat) inflater.inflate(R.layout.layer_guide, null);
        LottieAnimationView lottie_finger = ll.findViewById(R.id.lottie_finger);
        TextView textTip = ll.findViewById(R.id.textTip);
        String answerSum;

        if (guideIndex == 1) {
            answerSum = "答题可获得少量基础红包<br><font color='#ffe13b'>观看视频</font>可获得<font color='#ffe13b'>大量提现红包</font>";

            LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) textTip.getLayoutParams();
            params.setMarginStart(70);
            textTip.setLayoutParams(params);

            LinearLayout.LayoutParams paramsFinger = (LinearLayout.LayoutParams) lottie_finger.getLayoutParams();
            paramsFinger.setMarginStart(270);
            lottie_finger.setLayoutParams(paramsFinger);
        } else {
            View btnTouch = ll.findViewById(R.id.btnTouch);
            btnTouch.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    guideLister.onGuideClick();
                }
            });
            answerSum = "每次<font color='#ffe13b'>答对</font>问题都可以<br>获得红包奖励";
        }

        textTip.setText(Html.fromHtml(answerSum));

        return ll;
    }

    @Override
    public int getAnchor() {
        return Component.ANCHOR_BOTTOM;
    }

    @Override
    public int getFitPosition() {
        return Component.FIT_START;
    }

    @Override
    public int getXOffset() {
        return 0;
    }

    @Override
    public int getYOffset() {
        return -60;
    }

    public void setGuideClickLister(OnGuideClickLister lister) {
        this.guideLister = lister;
    }

    public interface OnGuideClickLister {
        void onGuideClick();
    }
}
